//
//  GoodsSelectedView.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/26.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "GoodsSelectedView.h"
#import "GoodsSelectedTableViewCell.h"
#import "GoodsPropertySelectedView.h"

static NSString *goodsSelectedCellID = @"goodsSelectedCellID";

@interface GoodsSelectedView ()<UITableViewDelegate, UITableViewDataSource>

@property (strong, nonatomic) UITableView *gooodsTableView;
@property (strong, nonatomic) GoodsPropertySelectedView *propertySelectedView;


@property (assign, nonatomic) NSInteger type;

//@property (strong, nonatomic) NSArray *array;

@end


@implementation GoodsSelectedView

- (instancetype)initWithType:(NSInteger)type andArray:(NSArray *)array {
    
    if (self = [super init]) {
        
        self.type = type;
        
        [self addSubview:self.gooodsTableView];
        
    }
    
    return self;
}

- (void)setContentDict:(NSDictionary *)contentDict {
    
    _contentDict = contentDict;
    
    [self.gooodsTableView reloadData];
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    [self.gooodsTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.mas_left);
        make.right.mas_equalTo(weakSelf.mas_right);
        make.top.mas_equalTo(weakSelf.mas_top);
        make.bottom.mas_equalTo(weakSelf.mas_bottom);
        
    }];

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return jisuan(80);
}

#pragma mark -delegate \ datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 4;
  
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    GoodsSelectedTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:goodsSelectedCellID];
    
    if (!cell) {
        
        cell = [[GoodsSelectedTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:goodsSelectedCellID];
    
    }
    
    cell.itemNum = indexPath.row;
    
    if (indexPath.row == 0) {
        
        cell.titleL.text = @"选择";
        cell.desL.text = @"颜色、尺寸";

        
    }else if (indexPath.row == 3) {
        
        cell.titleL.text = @"说明";
        cell.desL.text = @"不支持7天无理由退换";

    
    }else if (indexPath.row == 1) {
        
        cell.titleL.text = @"配送";
        cell.desL.text = self.contentDict[@"addressname"];
        
    }else  {
        
        cell.titleL.text = @"运费";
        cell.desL.text = self.contentDict[@"kdmoney"];
    
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSLog(@"地址、颜色、大小选择");
    
    // 颜色、大小选择
//    [self createPropertySelectedView];
    
}
- (void)createPropertySelectedView {
    
    GoodsPropertySelectedView *selectedView = [[GoodsPropertySelectedView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) withHeight:jisuan(800) andControllerType:self.type];
    selectedView.presentingVC = self.parentVC;
    
    UIWindow *window =  [UIApplication sharedApplication].keyWindow;
    window.windowLevel = 1;
    [window addSubview:selectedView];
    [selectedView show];
    
}

#pragma mark -lazy
- (UITableView *)gooodsTableView {
    
    if (!_gooodsTableView) {
        
        _gooodsTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        
        _gooodsTableView.delegate = self;
        _gooodsTableView.dataSource = self;
        
        _gooodsTableView.scrollEnabled = NO;
        
        _gooodsTableView.estimatedRowHeight = 0;
        _gooodsTableView.estimatedSectionFooterHeight = 0;
        _gooodsTableView.estimatedSectionHeaderHeight = 0;
        
        _gooodsTableView.showsVerticalScrollIndicator = NO;
        _gooodsTableView.showsHorizontalScrollIndicator = NO;
        
        _gooodsTableView.estimatedRowHeight = 0;
        _gooodsTableView.estimatedSectionHeaderHeight = 0;
        _gooodsTableView.estimatedSectionFooterHeight = 0;
        
        _gooodsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        if (@available(iOS 11.0, *)) {
            
            _gooodsTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
    }
    
    return _gooodsTableView;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
